const { ccclass, property } = cc._decorator;
import baseManager from '../../../base/baseManager';

@ccclass
export default class timerManager extends baseManager {

    private timers: Map<string, cc.Component> = new Map();

    clear() {
        this.timers.forEach((timer) => {
            this.node.removeComponent(timer);
        })
        this.timers.clear();
    }

    delete(rootName: string) {
        const timer = this.timers.get(rootName);
        if (timer) {
            this.timers.delete(rootName);
            this.node.removeComponent(timer);
        }
    }

    get(rootName: string): cc.Component {
        if (typeof rootName === 'undefined') {
            return null;
        }
        if (this.timers.has(rootName)) {
            return this.timers.get(rootName);
        }

        const timer = this.node.addComponent(cc.Component);
        this.timers.set(rootName, timer);
        return timer;
    }
}
